package com.sia.springcloud.result;

import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: Sirius
 * @Date: 2021/9/21 0:59
 * @Description:
 **/
public class ResultUtil {

    /**
     * 创建一个返回成功信息的json字符串
     *
     * @param message
     * @return
     */
    public static String createSimpleSuccessJson(String message) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("result", "Y");
        map.put("message", message);
        return JSON.toJSONString(map).toString();
    }


    /**
     * 创建一个返回失败信息的json字符串
     *
     * @param message
     * @return
     */
    public static String createSimpleFailureJson(String message) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("result", "N");
        map.put("message", message);
        return JSON.toJSONString(map).toString();
    }

    /**
     * 创建一个返回成功信息的json字符串
     *
     * @param objectList
     * @return
     */
    public static Map<String, Object> createSimpleSuccessObject(List<Object> objectList) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("result", "Y");
        map.put("objectList", objectList);
        return map;
    }


    /**
     * 创建一个返回失败信息的json字符串
     *
     * @param objectList
     * @return
     */
    public static Map<String, Object> createSimpleFailureObject(List<Object>  objectList) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("result", "N");
        map.put("objectList",objectList);
        return map;
    }


}

